//
//  PersonalViewController.m
//  SheShiDu
//
//  Created by 单剑秋 on 16/6/11.
//  Copyright © 2016年 单剑秋. All rights reserved.
//

#import "PersonalViewController.h"
#import "PersonalTableViewCell.h"
#import "UserCell.h"
#import "JQButton.h"

#define HEIGHT self.view.frame.size.height
#define WIDTH self.view.frame.size.width
@interface PersonalViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, retain)UITableView *personalTableView;

@end

@implementation PersonalViewController

- (void)viewWillAppear:(BOOL)animated
{
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self createTableView];
}

- (void)createTableView
{
    
    self.personalTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 49) style:UITableViewStylePlain];
    _personalTableView.delegate = self;
    _personalTableView.dataSource = self;
    [self.view addSubview:_personalTableView];
    
    [_personalTableView registerClass:[PersonalTableViewCell class] forCellReuseIdentifier:@"PersonalCell"];
    [_personalTableView registerClass:[UserCell class] forCellReuseIdentifier:@"UserCell"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 5;
    } else {
        return 3;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            UserCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UserCell" forIndexPath:indexPath];
            cell.backgroundImgView.image = [UIImage imageNamed:@"effect"];
            [cell.messageButton setImage:[UIImage imageNamed:@"message"] forState:UIControlStateNormal];
            [cell.userButton setImage:[JQImageView jq_captureCircleImage:[UIImage imageNamed:@"head"]] forState:UIControlStateNormal];
            [cell.setUpButton setImage:[UIImage imageNamed:@"setUp"] forState:UIControlStateNormal];
            cell.telephoneLabel.text = @"18625864798";
            cell.positionImgView.image = [UIImage imageNamed:@"position"];
            cell.positionLabel.text = @"哈尔滨  Harbin";
            [cell.orderButton setImage:[UIImage imageNamed:@"order"] forState:UIControlStateNormal];
            [cell.orderButton setTitle:@"我的订单" forState:UIControlStateNormal];
            [cell.livingButton setImage:[UIImage imageNamed:@"living"] forState:UIControlStateNormal];
            [cell.livingButton setTitle:@"直播间" forState:UIControlStateNormal];
            [cell.renovateButton setImage:[UIImage imageNamed:@"renovate"] forState:UIControlStateNormal];
            [cell.renovateButton setTitle:@"装修日志" forState:UIControlStateNormal];
            return cell;
        } else {
            PersonalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PersonalCell" forIndexPath:indexPath];
            if (indexPath.row == 1) {
                cell.functionImgView.image = [UIImage imageNamed:@"home"];
                cell.functionLabel.text = @"房屋信息";
            } else if (indexPath.row == 2) {
                cell.functionImgView.image = [UIImage imageNamed:@"calculator"];
                cell.functionLabel.text = @"费用计算器";
            } else if (indexPath.row == 3) {
                cell.functionImgView.image = [UIImage imageNamed:@"loan"];
                cell.functionLabel.text = @"装修贷款";
            } else {
                cell.functionImgView.image = [UIImage imageNamed:@"financial"];
                cell.functionLabel.text = @"理财服务";
            }
            cell.symbolImgView.image = [UIImage imageNamed:@"right"];
            return cell;
        }
    } else {
        PersonalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PersonalCell" forIndexPath:indexPath];
        if (indexPath.row == 0) {
            cell.functionImgView.image = [UIImage imageNamed:@"opinion"];
            cell.functionLabel.text = @"意见投诉";
        } else if (indexPath.row == 1) {
            cell.functionImgView.image = [UIImage imageNamed:@"telephone"];
            cell.functionLabel.text = @"咨询电话";
            cell.telephoneLabel.text = @"0451-88888888";
        }
        else {
            cell.functionImgView.image = [UIImage imageNamed:@"about"];
            cell.functionLabel.text = @"关于设饰度";
        }
        cell.symbolImgView.image = [UIImage imageNamed:@"right"];
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    int Height = 0;
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            Height = HEIGHT / 12 * 5;
        } else {
            Height = HEIGHT / 13;
        }
    } else {
        Height = HEIGHT / 13;
    }
    return Height;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0;
    } else {
        return 15;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
